home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_ShrinkMenu.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  2KB  |  94 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. **
  6. **  :ts=4
  7. */
  8.  
  9. #include "gtlayout_global.h"
  10.  
  11. #ifdef DO_MENUS
  12.  
  13.     /* LTP_ShrinkMenu(RootMenu *Root,ItemNode *First,ItemNode *Last,UWORD Mask):
  14.      *
  15.      *    Rethink the widths of all menu items between First and Last, including
  16.      *    both the first and the last entry.
  17.      */
  18.  
  19. VOID __regargs
  20. LTP_ShrinkMenu(RootMenu *Root,ItemNode *First,ItemNode *Last,UWORD Mask)
  21. {
  22.     ItemNode    *Here;
  23.     UWORD         Width,MaxWidth = 0,CommandWidth = 0;
  24.  
  25.         // Determine the widths of all items, also calculate
  26.         // the command widths
  27.  
  28.     for(Here = First ; Here -> Node . mln_Succ ; Here = (ItemNode *)Here -> Node . mln_Succ)
  29.     {
  30.         if((Here -> Flags & ITEMF_IsSub) == Mask)
  31.         {
  32.             if(!(Here -> Flags & ITEMF_IsBar))
  33.             {
  34.                 struct IntuiText *IntuiText = (struct IntuiText *)Here -> Item . ItemFill;
  35.  
  36.                 Width = 2 + TextLength(&Root -> RPort,IntuiText -> IText,strlen(IntuiText -> IText)) + 2;
  37.  
  38.                 if(Here -> Item . Flags & CHECKIT)
  39.                     Width += 2 + Root -> CheckWidth;
  40.  
  41.                 if(Width > MaxWidth)
  42.                     MaxWidth = Width;
  43.  
  44.                 if((Width = LTP_GetCommandWidth(Root,Here)) > CommandWidth)
  45.                     CommandWidth = Width;
  46.             }
  47.         }
  48.  
  49.         if(Here == Last)
  50.             break;
  51.     }
  52.  
  53.         // Now adjust the widths of all objects
  54.  
  55.     for(Here = First ; Here -> Node . mln_Succ ; Here = (ItemNode *)Here -> Node . mln_Succ)
  56.     {
  57.         if((Here -> Flags & ITEMF_IsSub) == Mask)
  58.         {
  59.             if(Here -> Flags & ITEMF_IsBar)
  60.             {
  61.                 struct Image *Image = (struct Image *)Here -> Item . ItemFill;
  62.  
  63.                 Image -> Width = MaxWidth + CommandWidth - 4;
  64.             }
  65.             else
  66.             {
  67.                     // Move over the submenu items if necessary
  68.  
  69.                 if(Here -> Item . SubItem)
  70.                 {
  71.                     ItemNode *Sub = (ItemNode *)((ULONG)Here -> Item . SubItem - sizeof(struct MinNode));
  72.  
  73.                     for(;;)
  74.                     {
  75.                         Sub -> Item . LeftEdge = MaxWidth + 2;
  76.  
  77.                         if(Sub -> Item . NextItem)
  78.                             Sub = (ItemNode *)Sub -> Node . mln_Succ;
  79.                         else
  80.                             break;
  81.                     }
  82.                 }
  83.             }
  84.  
  85.             Here -> Item . Width = MaxWidth + CommandWidth;
  86.         }
  87.  
  88.         if(Here == Last)
  89.             break;
  90.     }
  91. }
  92.  
  93. #endif    /* DO_MENUS */
  94.